package org.kimoji.global.service;

import java.util.List;

import javax.annotation.PostConstruct;

import org.kimoji.entity.Category;
import org.kimoji.entity.User;
import org.kimoji.global.dao.GlobalDAO;
import org.kimoji.global.tool.CacheTool;
import org.kimoji.personal.dao.PersonalDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GlobalService {

	@Autowired
	private GlobalDAO globalDAO;
	@Autowired
	private PersonalDAO personalDAO;
	
	/**
	 * 系統初始化
	 * <strong>Description</strong>:
	 * @return void
	 * @author chok
	 * 2014-2-1
	 */
	@PostConstruct
	public void systemInit(){
		//加載所有用戶信息至緩存
		cacheAllUser();
		//加載類別信息至緩存
		cacheCategory();
	}
	
	public List<Category> showCategory(){
		return globalDAO.getCacheCategories();
	}
	
	public void cacheAllUser(){
		List<User> users = personalDAO.loadAllUser();
		personalDAO.cacheAllUser(users);
	}
	
	public void cacheCategory(){
		List<Category> categories = globalDAO.getCategories();
		globalDAO.cacheCategories(categories);
	}
	
	
}
